@extends('admin.layout')
@section('content')
@section('title',$title)
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                {{$title}}
                <small>更快的管理您的广告信息
                    @if(session('info'))
                        <span id="info" class="text-red">{{session('info')}}</span>
                    @endif
                </small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{{url('/admin/index')}}"><i class="fa fa-dashboard"></i> Home</a></li>
                <li><a href="{{url('/admin/change/itvadd')}}">广告添加</a></li>
                <li class="active">广告列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看广告列表</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">

                               <form action="{{url('/admin/change/itvindex')}}">
                                   <div class="row">
                                        <div class="col-md-2">
                                           <div class="form-group">
                                                <select name="num" class="form-control">
                                                    <option
                                                    @if(!empty($request['num']) && $request['num'] == 10) selected="selected"
                                                    @endif>10</option>
                                                    <option
                                                    @if(!empty($request['num']) && $request['num'] == 20) selected="selected"
                                                    @endif>20</option>
                                                    <option
                                                    @if(!empty($request['num']) && $request['num'] == 50) selected="selected"
                                                    @endif>50</option>
                                                    <option
                                                    @if(!empty($request['num']) && $request['num'] == 100) selected="selected"
                                                    @endif>100</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-4 col-md-offset-6" >
                                            <div class="input-group input-group-sm">
                                               <input name="keywords"
                                                value="{{$request['keywords']  or  ''}}" type="text" class="form-control">
                                               <span class="input-group-btn">
                                              <button class="btn btn-info btn-flat" type="submit">搜索</button>
                                              </span>
                                            </div><!-- /input-group -->
                                        </div>
                                   </div>

                               </form>
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>广告主</th>
                                    <th>广告主域名</th>
                                    <th>赞助费</th>
                                    <th>广告图片</th>
                                    <th>   操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach( $data as $row)
                                <tr>
                                    <td>{{$row -> id}}</td>
                                    <td class='td_name'>{{$row -> name}}</td>
                                    <td class='td_url'>{{$row -> url}}</td>
                                    <td>{{$row -> money}}</td>
                                    <td><img src="{{asset($row -> pic)}}" alt="" width="30"/></td>
                                    <td>
                                        <a href="{{ url('/admin/change/itvedit') }}/{{ $row -> id }}">编辑</a>
                                        <a onclick="return confirm('确认要删除吗?');" href="{{ url('/admin/change/itvdelete') }}/{{ $row -> id }}">删除</a>
                                    </td>
                                </tr>
                                @endforeach
                                </tfoot>
                            </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    //点击修改信息
    <script>


        window.onload = function()
        {
            //配置ajax选项
                  $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                  });
            var dbl = true;
            $('.td_name').on('dblclick',function()
            {
                  if(!dbl) return ;
                  dbl = false;
                  var td = $(this);
                  var oldValue = $(this).html();
                  var id = $(this).prev().html();
                  var inp = $('<input type="text" value="">');
                  inp.val(oldValue);
                  $(this).html(inp);
                  inp.select();
                  inp.on('blur',function()
                  {
                      var newValue = $(this).val();
                      $.ajax({
                           url:"{{ url('/admin/change/itvname') }}",
                           type:'GET',
                           data:{id:id,name:newValue},
                           success:function(data)
                           {
                                if(data == 0)
                                {
                                    td.html(newValue);
                                }else
                                {
                                    td.html(oldValue);
                                }
                           },
                           error:function()
                           {

                           },
                           dataType:'TEXT'
                      });
                     dbl = true;
                  });
            });
            $('#info').fadeOut(1000);
        }

    </script>
@endsection